package com.example.demo.oo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public abstract class BaseService<T>  {

    @Autowired
    JpaRepository<T, Integer> repository;

    protected T of(T t) {
        Example<T> example = Example.of(t);
        return repository.findOne(example).orElse(t);
    }

    protected T of(Integer id) {
        return repository.getOne(id);
    }

    protected void save(T t) {
        repository.save(t);
    }


    protected void delete(T t) {
        repository.delete(t);
    }

}
